package com.gangye;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

/**
 * @Classname OCRIdentifyDemo
 * @Description OCR影像识别
 * @Date 2020/4/15 15:25
 * @Created by gangye
 */
public class OCRIdentifyDemo {
    public static void main(String[] args) {
        ITesseract iTesseract = new Tesseract();
        iTesseract.setDatapath("tesseract-ocr");  //相对路径，这个时候tesseract目录和src目录平级
//        iTesseract.setDatapath("F:\\java\\idea-workspace\\OCRDemo\\tesseract-ocr"); //绝对路径

        iTesseract.setLanguage("chi_sim");  //选择字库文件（只需写文件名即可，不用添加文件后缀）
        try {
            File imageFile = new File("多线程.jpg");
            String identifyResult = iTesseract.doOCR(imageFile);
            //打印图片内容
            System.out.println(identifyResult);
        } catch (TesseractException e) {
            System.out.println(e.toString());
        }
    }
}
